/**
 * 
 */
package com.xintoucloud.gsv.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xintoucloud.gsv.entity.SupervisionType;
import com.xintoucloud.gsv.service.SupervisionTypeService;

/**
 * @author xiang
 *
 */
@Controller@RequestMapping("/supervisionType")
public class SupervisionTypeController {

	@Autowired
	private SupervisionTypeService supervisionTypeService;
	
	@RequestMapping("/insert")
	public String showSupervisionType() {
		return "duchatype";
	}
	
	@RequestMapping("/list")
	@ResponseBody
	public Map<String,Object> list() {
		Map<String,Object> map = new HashMap<String,Object>();
		List<SupervisionType> list = supervisionTypeService.list();
		map.put("code", 0);
		map.put("data", list);
		return map;
	}
	
	@PostMapping("/addSupervisionType")
	public String addSupervisionType(SupervisionType supervisionType) {
		supervisionTypeService.addSupervisionType(supervisionType);
		return "redirect:insert";
	}
	
	@PostMapping("/deleteSupervisionType")
	public String deleteSupervisionType(HttpServletRequest request) {
		String sid = request.getParameter("sid");
		supervisionTypeService.deleteSupervisionType(Integer.parseInt(sid));
		return "redirect:insert";
	}
	
	@PostMapping("/updateSupervisionType")
	public String supervisionTypeService(SupervisionType supervisionType) {
		supervisionTypeService.updateSupervisionType(supervisionType);
		return "redirect:insert";
	}
	
}
